package system;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements Operation{
    @Override
    public void work(BookList bookList) {

        Scanner scan = new Scanner(System.in) ;
        System.out.println("输入你要归还的图书的书名");
        String name = scan.nextLine() ;
        int currentSize = bookList.getUsedSize();
        for(int i = 0 ;i < currentSize ; i ++){
            Book book = bookList.getBook(i) ;
            if (book.getName().equals(name)) {
                if(book.getIsBorrowed() == true){
                    book.setIsBorrowed(false);
                    System.out.println("归还成功");
                    return ;
                }else{
                    System.out.println("已归还，请勿重复归还操作");
                    return ;
                }
            }
        }
        System.out.println("没有你要归还的书籍");
    }
}
